<?php
function __autoload($class){
	require_once '../'.$class.'.php';
}

$teamNameExists = 0;
$teamAdded = 0;

$realteam = new RealTeam("name");
if(isset($_POST['submit'])){
	$realteam = new RealTeam($_POST['teamname']);
	if(!$realteam->validationName()){
		$dbconnect = new DBconnect();
		if(!$dbconnect->isExistsTeamName($realteam)){
			$dbconnect->addRealTeam($realteam);
			$teamAdded = 1;
		}
		else {
			$teamNameExists = 1;
		}
	}
}
require_once 'adminHeader.php';
?>
	<form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post'>
		<table>
			<th>Add Team</th>
			<tr>
				<td>Team Name</td>
				<td><input type='text' name='teamname'></td>
				<td><?php 
				if($realteam->validationName()) echo "Please enter team name!";
				if($teamNameExists) echo "This team exists in database!";
				?>
				</td>
			</tr>
			<tr>
				<td></td>
				<td><input type='submit' name='submit' value='Add Team'></td>
			</tr>
		</table>
	</form>
	<?php 
		if($teamAdded) echo $_POST['teamname']." added in database!";
		require_once 'adminFooter.php';
	?>

